package com.example.emos.api;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;

import java.net.InetAddress;
import java.net.UnknownHostException;

@SpringBootApplication
@ServletComponentScan
@Slf4j
@EnableAsync
public class EmosApiApplication {

    public static void main(String[] args) throws UnknownHostException {
//        SpringApplication app = new SpringApplication(EmosApiApplication.class);
//        Environment env = app.run(args).getEnvironment();
//        log.info("启动成功！！！");
//        log.info("地址：\thttp://127.0.0.1:{}",env.getProperty("server.port"));

        ConfigurableApplicationContext application = SpringApplication.run(EmosApiApplication.class, args);
        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        log.info("\n----------------------------------------------------------\n\t" +
                "Application  is running! Access URLs:\n\t" +
                "Local访问网址: \t\thttp://localhost:" + port + path + "\n\t" +
                "External访问网址: \thttp://" + ip + ":" + port + path + "\n\t" +
                "----------------------------------------------------------");

    }
}